import { GLItem } from './GLItem';
import { GLFolder } from './GLFolder';
import { GLAPI } from './GLAPI.service';
import { GLFolderContainer } from './GLFolderContainer';

export class GLBook extends GLItem implements GLFolderContainer {
  private url: string;

  constructor(data, private glAPI: GLAPI, parentFolder?: GLFolder) {
    super(parentFolder, data.name, data.gl_uri);
    this.url = data.url;
    glAPI.isBookAvailable(this.id).then((found: boolean) => {
      this.available = found;
    }).catch(console.error);
  }

  asFolder() {
    return this.glAPI.getBook(this.id, this.url, this.getParentFolder());
  }
}
